package com.ym.health.api.others;

import com.github.pagehelper.PageInfo;
import com.ym.common.constant.Constants;
import com.ym.common.utils.page.PageDomain;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.core.shiro.ShiroUtil;
import com.ym.core.utils.tkmybatis.TK;
import com.ym.medical.domain.entity.HosSosEntity;
import com.ym.medical.domain.param.HosSosQryParam;
import com.ym.medical.domain.param.HospitalQueryParam;
import com.ym.medical.domain.vo.HosSosVo;
import com.ym.medical.domain.vo.HospitalDetailVo;
import com.ym.medical.domain.vo.HospitalListVO;
import com.ym.medical.service.IHospitalSV;
import com.ym.soso.service.IHosSosSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author wenbo
 * @date 2020-08-19
 */
@Api(tags = "app-【医院】")
@RestController
@Validated
@RequestMapping(value = "/others/hospital",headers= Constants.Api.VERSION)
public class HospitalController extends BaseController {

    @Autowired
    private IHospitalSV hospitalSV;

    @Autowired
    private IHosSosSV iHosSosSV;

    @ApiOperation("查询【医院】列表")
    @Log(dataBase = false, printBody = false, printQuery = true)
    @GetMapping("/list")
    public APIResponse<PageInfo<HospitalListVO>> list(@Valid HospitalQueryParam queryParam) {
        PageDomain.startPage();
        List<HospitalListVO> list = hospitalSV.selectHospitals(queryParam);
        return successPage(list);
    }

    @ApiOperation("获取医院详细信息")
    @Log(dataBase = false, printBody = false, printQuery = true)
    @GetMapping(value = "/info")
    public APIResponse<HospitalDetailVo> info(@RequestParam Long id) {
        Long currId = ShiroUtil.getLoginId();
        HospitalDetailVo detailVo = hospitalSV.resultMap(id, currId);
        return successData(detailVo);
    }

    @Log(dataBase = true, printBody = false)
    @ApiOperation("医院急救查询")
    @GetMapping("/hospital/sos")
    @ResponseBody
    public APIResponse<HosSosEntity> hospitalSos(
            @ApiParam(name = "id", value = "医院id", required = true)
            @RequestParam Long id) {
        TK tk = TK.select(HosSosEntity.class).where().andEqualTo(HosSosEntity::getHosId,id).end();
        HosSosEntity hosSos = iHosSosSV.selectOne(tk);
        return APIResponse.success(hosSos);
    }

    @Log(dataBase = true, printBody = false)
    @ApiOperation("一般急救查询")
    @GetMapping("/hosSos")
    @ResponseBody
    public APIResponse hosSos(
            @RequestParam(name = "pageNum", defaultValue = "1", required = false) int pageNum,
            @RequestParam(name = "pageSize", defaultValue = "10", required = false) int pageSize,
            HosSosQryParam sosQryParam) {
        PageInfo<HosSosVo> hospitals = iHosSosSV.hosSos(pageNum, pageSize, sosQryParam);
        return APIResponse.success(hospitals);
    }



}
